<div th:replace="admin/module/_header"></div>

<div class="wrapper">
    <!-- 菜单栏模块 -->
    <div th:replace="admin/module/_sidebar"></div>
    <div class="content-wrapper">
        <section class="content-header">
            <h1 style="display: inline-block;">权限管理</h1>
            <ol class="breadcrumb">
                <li>
                    <a data-pjax="true" href="/admin"><i
                            class="fa fa-dashboard"></i> 首页</a>
                </li>
                <li><a data-pjax="true" href="#">权限管理</a></li>
                <li class="active">权限列表</li>
            </ol>
        </section>
        <section class="content container-fluid">
            <div class="row">
                <div class="col-xs-12" style="margin-bottom: 10px;">
                    <a class="btn btn-primary" href="/admin/permission/new">
                        <i class="fa fa-plus"></i> 新增
                    </a>
                </div>
                <div class="col-md-8">
                    <div class="nav-tabs-custom">
                        <div class="box box-primary">
                            <div class="box-body table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                    <tr>
                                        <th>名称</th>
                                        <th>路径</th>
                                        <th>类型</th>
                                        <th>名称</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr th:each="permission : ${permissionList}">
                                        <td th:class="'permission-level-'+${permission.level}">
                                            <i th:class="${permission.icon}"></i>&nbsp;[[${permission.name}]]
                                        </td>
                                        <td>[[${permission.url}]]</td>
                                        <td>
                                            <span style="color: #ca195a;font-weight: bold;"
                                                  th:if="${permission.resourceType == 'menu'}">菜单</span>
                                            <span th:if="${permission.resourceType == 'button'}">接口</span>
                                            <span th:if="${permission.resourceType == 'page'}">页面</span>
                                        </td>
                                        <td>
                                            <a th:href="'/admin/permission/edit?id='+${permission.id}"
                                               class="btn btn-primary btn-xs ">修改
                                            </a>
                                            <button class="btn btn-danger btn-xs "
                                                    th:onclick="'removeIt('+${permission.id}+')'">删除
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div class="box-footer clearfix">
                                <div class="no-margin pull-left">
                                    第 [[${pageInfo.current}]] / [[${pageInfo.pages}]] 页
                                </div>
                                <ul class="pagination no-margin pull-right">
                                    <li><a data-pjax="true" th:classappend="${pageInfo.current == 1 ? 'disabled' : ''}"
                                           class="btn btn-sm"
                                           th:href="'/admin/permission'">
                                        首页
                                    </a>
                                    </li>
                                    <li><a data-pjax="true" class="btn btn-sm"
                                           th:classappend="${pageInfo.current == 1 ? 'disabled' : ''}"
                                           th:href="'/admin/permission?page='+${pageInfo.current-1}">
                                        上一页
                                    </a>
                                    </li>
                                    <li><a data-pjax="true" class="btn btn-sm"
                                           th:classappend="${pageInfo.current == pageInfo.pages ? 'disabled' : ''}"
                                           th:href="'/admin/permission?page='+${pageInfo.current+1}">
                                        下一页
                                    </a>
                                    </li>
                                    <li><a data-pjax="true" class="btn btn-sm"
                                           th:classappend="${pageInfo.current == pageInfo.pages ? 'disabled' : ''}"
                                           th:href="'/admin/permission?page='+${pageInfo.pages}">
                                        尾页
                                    </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="nav-tabs-custom">
                        <div class="box box-primary">
                            <div class="box-body table-responsive">
                                <div class="box-header with-border">
                                    <h3 class="box-title">权限树</h3>
                                </div>
                                <div class="form-group">
                                    <ul id="permission" class="ztree"></ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <script  th:inline="javascript">
            // ztree文档地址：http://www.treejs.cn/v3/api.php
            var setting = {
                view: {
                    addHoverDom: false,
                    removeHoverDom: false,
                    selectedMulti: false,
                    showIcon: false,
                    showLine: false
                },
                check: {
                    enable: true,
                    chkboxType: {"Y": "p", "N": ""}
                },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "pid",
                        rootPId: 0
                    }
                },
                edit: {
                    enable: false
                }
            };

            // 初始化
            var permissions = [[${permissions}]]
            $.fn.zTree.init($("#permission"), setting, permissions);



            function removeIt(id) {
                layer.confirm('你确定是否删除', function (index) {
                    $.ajax({
                        type: 'DELETE',
                        url: '/admin/permission/delete?id=' + id,
                        async: false,
                        success: function (data) {
                            if (data.code == 0) {
                                showMsg(data.msg, "error", 1000);
                            } else {
                                window.location.reload();
                            }

                        }
                    });
                    layer.close(index);
                });
            }

        </script>
    </div>
</div>
<div th:replace="admin/module/_footer"></div>

